@RestController
@RequestMapping("/api/ratings")
public class RatingController {
    @Autowired
    private RatingService ratingService;

    @PostMapping("/rate")
    public ResponseEntity<?> rateSong(@RequestBody RatingRequest ratingRequest) {
        Long userId = ratingRequest.getUserId();
        Long songId = ratingRequest.getSongId();
        int rating = ratingRequest.getRating();

        Rating savedRating = ratingService.rateSong(userId, songId, rating);
        if (savedRating != null) {
            return ResponseEntity.ok(savedRating);
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("评分失败");
        }
    }
}
